<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{data.title}}</block>
		</cu-custom>
		<view>
			<view class="content-nav padding-xs bg-white">
				<view class="bg-white nav">
					<view class="cu-item" @click="LoadLearner(1,'learned')" :class="currview=='learned'?'cur':''">已学习</view>
					<view class="cu-item" @click="LoadLearner(1,'bought')" :class="currview=='bought'?'cur':''">已购买</view>
					<view class="cu-item" @click="LoadLearner(1,'collected')" :class="currview=='collected'?'cur':''">已订阅</view>
				</view>
			</view>
			<view class="text-gray text-center" v-if="data.list.length==0">
				<text class="text-empty">空空如也</text>
			</view>
			<view class="padding" v-else>
				<view class="cu-list menu-avatar comment user-card">
					<view @tap="naviTo('index/dialog',{uid:item.uid})" class="cu-item" v-for="(item, index) in data.list" :key="index">
						<view class="cu-avatar round xl" :style="'background-image:url('+item.avatar+');'"></view>
						<view class="content">
							<view class="text-bold">
								<text class="text-cut">{{item.nickname}}</text>
							</view>
							<view class="text-muted text-content text-df">
								<text v-if="currview=='learned'">于{{item.paydate}}学习了《{{item.title}}》，学到{{item.datetime}}</text>
								<text v-else-if="currview=='collected'">于{{item.paydate}}关注了你</text>
								<text v-else>
									于{{item.paydate}}购买了{{item.title}}
									<text v-if="item.expired" class="text-red">已到期</text>
								</text>
							</view>
						</view>
						<view class="action">
							<view class="text-xxl text-boldm text-green"><text class="cuIcon-community"></text></view>
						</view>
					</view>
				</view>
				<view class="padding text-center" v-if="loadmore=='more'">
					<view class="text-yellow text-lg" @click="LoadLearner(page+1, currview)">查看更多</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import core from "@/static/core.js"
	
	export default {
		data() {
			return {
				currview:'learned',
				page:1,
				loadmore:'more',
				data:{
					title:"hello",
					list:[]
				}
			}
		},
		onLoad(options) {
			if(core.userinfo.uid<=0) return core.toast('请先登录','login');
			if(typeof(options.act)!='undefined' && options.act) this.currview = options.act;
			this.LoadLearner(1,this.currview);
		},
		methods:{
			naviTo(page,data={}){
				return core.navito(page,data);
			},
			LoadLearner(page=1,cur='learned'){
				var that = this;
				return core.get('lector/learner',function(res){
					if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined') return core.report(res,page==1?true:false);
					that.page = page;
					that.currview = cur;
					if(page==1){
						that.data = res;
					}else{
						that.data.list = that.data.list.concat(res.list);
					}
					that.loadmore = that.data.list.length<15 ? 'noMore' : 'more';
				},{page:page,op:cur});
			}
		}
	}
</script>

<style>
	.cu-list.menu-avatar.comment>.cu-item .xl ~ .content{max-width: calc(100% - 100upx);}
</style>
